﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
using System.Drawing;
public partial class Manage_GoodsUpdate : System.Web.UI.Page
{
    string goodsid;
    public string strSql, status, iszx = "none";
    Int64 Accountid_QY;

    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckGoods);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            goodsid = SysFun.IsSQL(Request.QueryString["GoodsId"].ToString());
            if (!Page.IsPostBack)
            {
                //string goodscount;
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account != null)
                {
                    if (_Account.Sort == "0")
                    {
                        choose.Visible = false;
                    }
                    else
                    {
                        choose.Visible = true;
                    }
                 
                    Accountid_QY = SysFun.ToLong(_Account.AccountId);

                    string ComName = "";
                    Db db = new Db();
                    System.Data.IDataReader dr;
                    //取得商品信息
                    strSql = @" select goodsSYZ,isnull(dayEating,0) dayEating,  goodsOther_bc,goodsInsPack,  goodsOther_cctj,goodsOther_Effdate, goodsOther_CPBZ,isnull(goods_dwcc,0) goods_dwcc,memo2,productname_gjsp,Medicinemodel_gjsp,Outlookc_gjsp,Unit_gjsp,lastyearPayDuty,memo1, companyRegistermeney,PriceonlyDJ,ispPerformcountryprice,PriceliscensePW, dbo.Chk_GetCompanyName(AccountId_SC) as companyname_sc,AccountId_SC,AccountId_TJR, GoodsId, ProductId, GoodsName,  LicenseNumber, LicenseNumberDate, IsSurveyReport, SurveyReportId, SurveyReportDate,   ImportCode, ImportRegistDate, IsPrimitive, Pack, RetailPrice, CheckStatus, IsImport, Factor, PackUnit, Licence, LicenceDate, AccountId_SC, GoodsInstruction,  Material,  NoPass,  ImgUrl, memo4, memo5, shenhetime, IsDel, sh_discrible, ProductNameSM, AccountName_SHR, AccountName_TJR,   ischange,  QualitylevelsStandard, Qualitylevelstrustiness, QualitylevelsManage , ProductName,Medicinemodel,Outlookc,Unit from v_product_goods where goodsid='" + goodsid + "'";
                    dr = db.DataReader(strSql);
                    while (dr.Read())
                    {
                        Hpid.Value = dr["productid"].ToString();
                        labProductCode.Text = dr["productid"].ToString();
                        HAccountId_TJR.Value = dr["AccountId_TJR"].ToString();
                        HAccountId_TJname.Value = dr["AccountName_TJR"].ToString();
                        labProductName.Text = SysFun.ToTrim(dr["productname"].ToString());//商品通用名

                        string _strMedicinemodel = dr["medicinemodel"].ToString();
                        string _strOutlookc = dr["outlookc"].ToString();
                        labMedicinemodel.Text = _strMedicinemodel;
                        labOutlookc.Text = _strOutlookc;
                        labunit.Text = dr["unit"].ToString();
                        labprice.Text = SysFun.ToTrim(dr["memo1"]);

                        txtCompany.Text = dr["companyname_sc"].ToString();//生产企业名称
                        txtIsSalerId.Value = dr["AccountId_SC"].ToString();

                        status = "none";//默认不显示

                        if (dr["ispPerformcountryprice"].ToString() != "" && Convert.ToBoolean(dr["ispPerformcountryprice"]))//是否不执行国家价格
                        {
                            chkIsImport.Checked = true;
                            TextWJPW.Text = dr["PriceliscensePW"].ToString();
                            iszx = "block";
                            txtPriceonlyDJ.Text = dr["PriceonlyDJ"].ToString();
                        }


                        labunit.Text = SysFun.ToTrim(dr["unit"].ToString());

                        /********* goods部分********/
                        txtProductNameSM.Text = dr["ProductNameSM"].ToString();
                        txtFactor.Text = dr["factor"].ToString();
                        txtLicenseNumber.Text = dr["LicenseNumber"].ToString();
                        if (dr["LicenseNumberDate"] != "" && !dr["LicenseNumberDate"].ToString().Equals("1900-1-1 0:00:00"))
                        {
                            txtLicenseNumberDate.Text = dr["LicenseNumberDate"].ToString();
                        }
                        txtGoodsName.Text = dr["goodsname"].ToString();
                        txtMaterial.Text = dr["Material"].ToString();
                        if (dr["IsSurveyReport"].ToString() != "")
                        {
                            chkIsSurveyReport.Checked = Convert.ToBoolean(dr["IsSurveyReport"].ToString());
                        }
                        else
                        {
                            chkIsSurveyReport.Checked = false;
                        }
                        txtSurveyReportId.Text = dr["SurveyReportId"].ToString();
                        if (dr["SurveyReportDate"] != null && !dr["SurveyReportDate"].ToString().Equals("1900-1-1 0:00:00"))
                        {
                            txtSurveyReportDate.Text = dr["SurveyReportDate"].ToString();
                        }
                        txtFactor0.Text = dr["lastyearPayDuty"].ToString().Trim();
                        txtFactor1.Text = dr["companyRegistermeney"].ToString().Trim();
                        rdoQualitylevelsStandard.SelectedIndex = Convert.ToInt32(dr["QualitylevelsStandard"].ToString());
                        rdoQualitylevelstrustiness.SelectedIndex = Convert.ToInt32(dr["Qualitylevelstrustiness"].ToString());
                        RadioQualitylevelsManage.SelectedIndex = Convert.ToInt32(dr["QualitylevelsManage"].ToString());
                        txtGoodsInstruction.Text = dr["GoodsInstruction"].ToString();
                        //目录
                        txtproduct.Text = dr["productname_gjsp"].ToString();
                        txtmedici.Text = dr["Medicinemodel_gjsp"].ToString();
                        txtoutlookc.Text = dr["Outlookc_gjsp"].ToString();
                        txtunit.Text = dr["Unit_gjsp"].ToString();
                        if (dr["memo2"].ToString() != "") //有日服量 就允许打勾
                        {
                            labProductRFL.Text = dr["memo2"].ToString();
                            //是否符合日服量
                            CheckRFL.Checked = dr["dayEating"].ToString() != "0" ? true : false;
                            CheckRFL.Visible = true;
                        }

                        //包材
                        txtbC.Text = dr["goodsOther_bc"].ToString();
                        //包装规格
                        txtBZGG.Text = dr["goodsInsPack"].ToString();
                        //存储条
                        txtCCTJ.Text = dr["goodsOther_cctj"].ToString();
                        //是否低温存储
                        CheckDWCC.Checked = dr["goods_dwcc"].ToString() != "0" ? true : false;
                        //产品有效期
                        txtCPXQ.Text = dr["goodsOther_Effdate"].ToString();
                        //执行标准
                        txtZXBZ.Text = dr["goodsOther_CPBZ"].ToString();
                        //适应症
                        txtGoodsSYZ.Text = dr["goodsSYZ"].ToString();
                    }
                    db.Close();
                    dr.Close();
                    dr.Dispose();

                }
            }
        }
    }


    //审核通过
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        addGoods(11);
    }
    //审核不通过
    protected void BtnSave0_Click(object sender, EventArgs e)
    {
        addGoods(12);
    }
    //纸质一致
    protected void BtnSave1_Click(object sender, EventArgs e)
    {
        addGoods(13);
    }
    //未审核
    protected void BtnSave2_Click(object sender, EventArgs e)
    {
        addGoods(10);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }
    private void addGoods(int strMemo3)
    {
        DateTime ImportRegistDate = Convert.ToDateTime("1900-1-1");
        HZ.MBSM.Model.Goods goods = new HZ.MBSM.Model.Goods();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {

            Db db = new Db();

            int rowCun = 0;

            System.Data.IDataReader dr;
            strSql = "select count(GOODSID) as cun from dbo.GOODS where PRODUCTID='" + Hpid.Value.Trim() + "'  AND  FACTOR= '" + SysFun.ToTrim(SysFun.ToInt(txtFactor.Text)) + "' AND ACCOUNTID_SC=" + txtIsSalerId.Value + " and goodsid<>" + goodsid;
            dr = db.DataReader(strSql);
            if (dr.Read())
            {
                rowCun = SysFun.ToInt(dr["cun"]);
            }
            dr.Close();
            dr.Dispose();
            db.Close();
            if (rowCun > 0)
            {
                Response.Write("<script language=JavaScript>alert('该商品在数据库中已经存在！！！');window.close();</script>");
            }
            else
            {
                if (chkIsImport.Checked)
                {
                    if (TextWJPW.Text.Trim() == "")
                    {
                        Response.Write("<script language=JavaScript>alert('请填写物价批文发文号！！！');</script>");
                        return;
                    }
                    if (txtPriceonlyDJ.Text.Trim() == "")
                    {
                        Response.Write("<script language=JavaScript>alert('请填写单独定价价格！！！');</script>");
                        return;
                    }
                    else
                    {
                        if (!SysFun.IsNumeric(txtPriceonlyDJ.Text.Trim()))
                        {
                            Response.Write("<script language=JavaScript>alert('价格请填写数字！！！');</script>");
                            return;
                        }
                    }
                }
                goods.ProductId = Convert.ToInt64(Hpid.Value.ToString());
                goods.ispPerformcountryprice = chkIsImport.Checked;
                goods.PriceliscensePW = TextWJPW.Text.Trim();
                goods.PriceonlyDJ = txtPriceonlyDJ.Text.Trim();
                goods.GoodsId = Convert.ToInt64(goodsid);
                goods.AccountId_SC = SysFun.ToLong(txtIsSalerId.Value.ToString());
                goods.AccountId_TJR = Convert.ToInt64(HAccountId_TJR.Value.Trim());//添加人编码
                goods.AccountName_TJR = HAccountId_TJname.Value.Trim();//添加人编码

                goods.Factor = SysFun.ToInt(txtFactor.Text.ToString());//转换系数

                goods.GoodsInstruction = txtGoodsInstruction.Text.ToString();
                goods.GoodsName = txtGoodsName.Text.ToString();

                goods.IsSurveyReport = chkIsSurveyReport.Checked;

                goods.LicenseNumber = txtLicenseNumber.Text.ToString();
                if (txtLicenseNumberDate.Text != "")
                    goods.LicenseNumberDate = Convert.ToDateTime(txtLicenseNumberDate.Text.ToString());
                else
                    goods.LicenseNumberDate = Convert.ToDateTime("1900-1-1");

                goods.Material = txtMaterial.Text.ToString();
                goods.Pack = "";

                goods.QualityLevels = "3";

                if (txtSurveyReportDate.Text != "")
                    goods.SurveyReportDate = Convert.ToDateTime(txtSurveyReportDate.Text.ToString());
                else
                    goods.SurveyReportDate = Convert.ToDateTime("1900-1-1");
                goods.SurveyReportId = txtSurveyReportId.Text.ToString();

                goods.ProductNameSM = txtProductNameSM.Text;
                goods.QualitylevelsManage = RadioQualitylevelsManage.SelectedIndex;
                goods.QualitylevelsStandard = rdoQualitylevelsStandard.SelectedIndex;
                goods.Qualitylevelstrustiness = rdoQualitylevelstrustiness.SelectedIndex;
                switch (strMemo3) //10 未审核 11 通过 12 不通过 13 纸质一致
                {
                    case 10:
                        goods.NoPass = GetNOpss();
                        goods.CheckStatus = "1";
                        goods.AccountId_SH = _Account.AccountId;
                        goods.AccountName_SH = _Account.AccountName;
                        goods.shenhetime = System.DateTime.Now;
                        break;
                    case 11:
                        goods.NoPass = GetNOpss();
                        goods.CheckStatus = "1";
                        goods.AccountId_SH = _Account.AccountId;
                        goods.AccountName_SH = _Account.AccountName;
                        goods.shenhetime = System.DateTime.Now;
                        break;
                    case 12:

                        goods.NoPass = GetNOpss();
                        goods.CheckStatus = "2";
                        goods.AccountId_SH = _Account.AccountId;
                        goods.AccountName_SH = _Account.AccountName;
                        goods.shenhetime = System.DateTime.Now;
                        break;
                    case 13:
                        goods.NoPass = GetNOpss();
                        goods.CheckStatus = "3";
                        goods.AccountId_SH = _Account.AccountId;
                        goods.AccountName_SH = _Account.AccountName;
                        goods.shenhetime = System.DateTime.Now;
                        break;
                }

                //添加GMP信息
                HZ.MBSM.BLL.Goods goodsOperator = new HZ.MBSM.BLL.Goods();

                if (goodsOperator.CHeckgoodsjb(goods, strMemo3))
                {
                    goodsOperator.updatecompanyjb(txtFactor0.Text.Trim(), txtFactor1.Text.Trim(), HAccountId_TJR.Value.Trim(), true);

                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "goods", goods.GoodsId + goods.GoodsName + goods.GroupId + goods.ImportCode + goods.Licence + goods.LicenseNumberDate + goods.Material + goods.NewMedicine + goods.NewMedicineDate + goods.Pack + goods.PackUnit + goods.ProductId + goods.QualityLevels + goods.RetailPrice, "../Magage/goodsupdate.aspx", goods.NoPass, goods.GoodsId.ToString());
                    Response.Write("<script>alert('保存成功！！！');window.opener.location.reload();window.close();</script>");
                }
                else
                {
                    Response.Write("<script>alert('保存失败！！！');</script>");
                }
            }
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('请从新登录！！！');</script>");
        }
    }
    //获取审核不 通过原因
    private string GetNOpss()
    {
        System.Text.StringBuilder strnopass = new System.Text.StringBuilder();
        if (CheckBox1.Checked == true)
        {
            strnopass.Append("缺失注册批件 ！\n");
        }
        if (CheckBox2.Checked == true)
        {
            strnopass.Append("批准文号已过期！\n");
        }
        if (CheckZhiLiangCX.Checked == true)
        {
            strnopass.Append("缺失物价证明文件 ！\n");
        }
        if (CheckYaoPinJYBG.Checked == true)
        {
            strnopass.Append("物价证明文件已过期！\n");
        }
        if (CheckYaoPinYXQ.Checked == true)
        {
            strnopass.Append("缺失质量层次证明文件 ！\n");
        }
        if (CheckBox3.Checked == true)
        {
            strnopass.Append("缺失商品说明书！\n");
        }

        if (CheckBox4.Checked == true)
        {
            strnopass.Append("缺失检验报告单 ！\n ");
        }

        if (CheckBox6.Checked == true)
        {
            strnopass.Append("检验报告已过期 ！\n ");
        }
        if (CheckBoxNotall.Checked == true)
        {
            strnopass.Append("商品资料不全，请按“内部信息”栏目所列《资质预审资料要求》将商品资料装订成册，速递交至中心企管部！\n");
        }

        if (CheckJYBG.Checked == true)
        {
            strnopass.Append("需提交09年最新检验报告！\n");
        }
        if (Checkwjd.Checked == true)
        {
            strnopass.Append("需提交云南省物价单！\n");
        }
        if (CheckBoxRegister.Checked == true)
        {
            strnopass.Append("需提交注册批件或注册证！\n");
        }

        strnopass.Append(TxtNopass.Text.Trim());
        return strnopass.ToString();
    }

    /// <summary>
    /// 保存目录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnSave3_Click(object sender, EventArgs e)
    {
        if (!SysFun.IsNumeric(txtCPXQ.Text.Trim())) {
            Response.Write("<script>alert('产品有效期必须是数字！！！');</script>"); return;
        }
        HZ.MBSM.BLL.Goods goods = new HZ.MBSM.BLL.Goods();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (goods.SavaProduct(txtproduct.Text.Trim(), txtmedici.Text.Trim(), txtoutlookc.Text.Trim(), txtunit.Text.Trim(), CheckRFL.Checked ? "1" : "0", txtbC.Text.Trim(), txtBZGG.Text.Trim(), txtCCTJ.Text.Trim(), txtCPXQ.Text.Trim(), txtZXBZ.Text.Trim(), CheckDWCC.Checked ? "1" : "0", txtGoodsSYZ.Text.Trim(), _Account.AccountId.ToString(), goodsid))
        {
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "goods", goodsid + "|" + txtproduct.Text.Trim() + "|" + txtmedici.Text.Trim() + "|" + txtoutlookc.Text.Trim() + "|" + txtunit.Text.Trim(), "../Magage/goodsupdate.aspx", "修改目录", goodsid);
            Response.Write("<script>alert('保存成功！！！');</script>");
        }
        else
        {
            Response.Write("<script>alert('保存失败！！！');</script>");
        }

    }
   

    
}

